﻿using QuanLyKho.DTO;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Data.OleDb;
using System.Linq;
using System.Text;

namespace QuanLyKho.DAL
{
    class KhachHangDAO : DataProvider
    {
        public ArrayList GetListKhachHang()
        {
            string sqlString = "Select * from KhachHang";
            adapter = new OleDbDataAdapter(sqlString, connection);
            DataSet dataSet = new DataSet();
            adapter.Fill(dataSet);
            ArrayList listHangHoa = ConvertDataSetToArrayList(dataSet);

            return listHangHoa;
        }

        protected override object GetDataFromDataRow(DataTable dt, int i)
        {
            KhachHangDTO khachHangDTO = new KhachHangDTO();
            khachHangDTO.Ma = dt.Rows[i]["Ma"].ToString();
            khachHangDTO.Ten = dt.Rows[i]["Ten"].ToString();
            khachHangDTO.DiaChi = dt.Rows[i]["DiaChi"].ToString();
            khachHangDTO.Dt = dt.Rows[i]["DT"].ToString();

            return khachHangDTO;
        }

        public void insert(KhachHangDTO khachHangDTO)
        {
            string sqlString = "insert into KhachHang values('"
                + khachHangDTO.Ma + "','"
                + khachHangDTO.Ten + "','"
                + khachHangDTO.DiaChi + "','"
                + khachHangDTO.Dt + "','"
                + 0 + "')";
            ExecuteNonQuery(sqlString);
        }

        public ArrayList GetListKhachHangByTen(string tenKH)
        {
            string sqlString = "Select * from KhachHang"
                + " WHERE Ten = '" + tenKH + "'";
            adapter = new OleDbDataAdapter(sqlString, connection);
            DataSet dataSet = new DataSet();
            adapter.Fill(dataSet);
            ArrayList listHangHoa = ConvertDataSetToArrayList(dataSet);

            return listHangHoa;
        }
    }
}
